<?php

/*

  Action – Reaction	$4

  +1 Buy; +$3;
  Discard 2 cards.
  When another player plays an Attack card, you may set this aside from your hand. If you do, then at the start of your next turn, +1 Card and return this to your hand.

 */

class HorseTraders extends Card implements iAction, iKingdom, iReaction, iCornucopia, iReactingCard {

    private $reactConditions;

    public function __construct() {
        parent::__construct("Horse Traders", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;

        $this->reactConditions = new ReactionConditions();
        $this->reactConditions->action = array(Attack);
        $this->reactConditions->actor = array(SomeoneElse);
        $this->reactConditions->cardLocation = array(PlayHand);
        $this->reactConditions->limit = ForEachCard;
    }

    public function getDescription() {
        return array(
            "+1 Buy",
            "+$3",
            "Discard 2 cards.",
            "When another player plays an Attack card, you may set this aside from your hand. If you do, then at the start of your next turn, +1 Card and return this to your hand.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addBuys(1);
        $game->addMoney(new Price(3));
        ScreenDisplay::addScreenMessage($game, true, "get +1 buy and +3$", "gets +1 buy and +3$");

        $playHand = $game->getPlayHand();
        if (sizeof($playHand) > 2) {
            $output = MySocket::GetUserReply($game, Input_ChooseMany, $playHand, 2, 2, null, "Discard 2 cards");
            ScreenDisplay::addScreenMessage($game, false, " and discard" . nicePrint($output), " and discards " . sizeof($output) . " cards");
            foreach ($output as $p) {
                $game->moveCardFromPileToPile($p, PlayHand, DiscardPile);
            }
        } else {
            ScreenDisplay::addScreenMessage($game, false, " and discard" . nicePrint($playHand), " and discards " . sizeof($playHand) . " cards");
            $game->discardPlayHand();
        }
        $game->cardActionFinished();
        return true;
    }

    public function getConditions() {
        return $this->reactConditions;
    }

    public function isReactRelevant(Game $game, $card, $name) {
        return true;
    }

    public function react(Game $game, $card, $name) {
        ScreenDisplay::addScreenMessage($game, true, "reveal ".  nicePrint($this), "reveals ".  nicePrint($this), $name);
        $game->moveCardFromPileToPile($this, PlayHand, HorseTradersPile, $name);
        ScreenDisplay::addScreenMessage($game, false, " and set it aside", " and sets it aside");
        $game->setTempCard($card);
        return true;
    }

}

?>